/**
 * goio-bean
 * 
 * This class is the Person base bean
 * 
 * @link http://www.marcosperon.com/
 * @copyright 2009 - Peron Co.
 * @author Marcos Peron
 * @package com.marcosperon.bean
 * @version 2009
 */
package com.mperon.bean;

import javax.persistence.Entity;

/**
 * The Class Person.
 */
@Entity
public class Person extends Bean {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 2139278655741612958L;

    /** The first name. */
    private String firstName;

    /** The last name. */
    private String lastName;

    /** The person id. */
    private String personId;

    /**
     * Instantiates a new person.
     */
    public Person() {
        super();
    }

    /**
     * Gets the first name.
     * 
     * @return the first name
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the first name.
     * 
     * @param firstName
     *            the new first name
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Gets the last name.
     * 
     * @return the last name
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the last name.
     * 
     * @param lastName
     *            the new last name
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Sets the name.
     * 
     * @param name
     *            the new name
     */
    public void setName(String name) {
        if (name == null) {
            return;
        }
        if ("".equals(name)) {
            return;
        }
        int iSpacePosition = name.lastIndexOf(" ");
        if (iSpacePosition > -1) {
            setFirstName(name.substring(0, iSpacePosition - 1));
            setLastName(name.substring(iSpacePosition));
        } else {
            setFirstName(name);
            setLastName("");
        }
    }

    /**
     * Gets the name.
     * 
     * @return the name
     */
    public String getName() {
        StringBuilder fullName = new StringBuilder(getFirstName().length() + getLastName().length()
                + 1);
        fullName.append(getFirstName());
        if (!"".equals(getLastName())) {
            fullName.append(" ");
            fullName.append(getLastName());
        }
        return fullName.toString();
    }

    /**
     * Gets the person id.
     * 
     * @return the person id
     */
    public String getPersonId() {
        return personId;
    }

    /**
     * Sets the person id.
     * 
     * @param personId
     *            the new person id
     */
    public void setPersonId(String personId) {
        this.personId = personId;
    }
}
